package com.superbytecode.cloud.common.utils;

import lombok.experimental.UtilityClass;

import java.util.Collection;
import java.util.Map;

/**
 * All rights Reserved, Designed By www.super-master.cn
 *
 * @ProjectName: sanskrit
 * @Package: com.superbytecode.sanskrit.core.utils
 * @ClassName: AssertUtil
 * @Description: []
 * <p> </p>
 * @Author: [Lance Ting]
 * @Date: 2024/8/14 10:08
 * @Version: V1.0
 * @Copyright: 2024 www.super-master.cn Inc. All rights reserved.
 * TODO: 注意,本文件Lance Ting所作,如果转载或使用请标明具体出处!
 **/
@UtilityClass
public class AssertUtil {
    /**
     * 非空断言
     *
     * @param obj     value
     * @param message 异常信息
     */
    public void requireNonNull(Object obj, String message) {
        if (obj == null) throw new NullPointerException(message);
    }

    /**
     * 非空断言
     *
     * @param obj     value
     * @param message 异常信息
     */
    public void requireNonEmpty(Object obj, String message) {
        if (obj == null) throw new NullPointerException(message);
        if ((obj instanceof Collection) && ((Collection<?>) obj).isEmpty()//
                || (obj instanceof Map) && ((Map<?, ?>) obj).isEmpty() //
                || (obj instanceof String) && ((String) obj).isEmpty()//
        ) {
            throw new NullPointerException(message);
        }
    }

    /**
     * 布尔true断言
     *
     * @param positive 条件
     * @param message  异常信息
     */
    public void requirePositive(boolean positive, String message) {
        if (!positive) throw new IllegalArgumentException(message);
    }
}